define(["jquery", "easy-admin"], function ($, ea) {

    var init = {
        table_elem: '#currentTable',
        table_render_id: 'currentTableRenderId',
        index_url: 'evaluation.template/index',
        add_url: 'evaluation.template/add',
        edit_url: 'evaluation.template/edit',
        delete_url: 'evaluation.template/delete',
        export_url: 'evaluation.template/export',
        modify_url: 'evaluation.template/modify',
        // order_index_url:'evaluation.template/order',
        setQrcode_url:'evaluation.template/setQrcode',
    };

    var Controller = {

        index: function () {
            ea.table.render({
                init: init,
                toolbar: ['refresh','add',
                    // [{
                    //     text: ' 生成二维码',
                    //     open: init.setQrcode_url,
                    //     class: 'layui-btn layui-btn-normal layui-btn-sm layui-hide',
                    //     icon: 'fa fa-plus ',
                    //     title: '添加',
                    //     auth: 'order.html',
                    //     extend: ' data-full="true"',
                    // }]
                ],
                cols: [[
                    {type: 'checkbox'},
                    {field: 'id', title: 'ID',search:false},
                    {field: 'name', title: '模板名称'},
                    // {field: 'fields', title: '模板内容',search: false},
                    // {field: 'remark', title: '备注', templet: ea.table.text,search: false},
                    // {field: 'qr_code', title: '二维码',search: false, templet: ea.table.image},
                    // {field: 'systemAdmin.username', title: '二维码生成人',search: false},
                    {field: 'create_time', title: '创建时间', search: 'range'},
                    {
                        width: 250,
                        title: '操作',
                        templet: ea.table.tool,
                        operat: [
                            'edit',
                            [{
                                class: 'layui-btn layui-btn-normal layui-btn-xs',//
                                method: 'open',
                                text: '生成二维码',
                                auth: 'setQrcode',
                                url: init.setQrcode_url,
                                // extend: 'data-full="true"',
                            },
                            // {
                            //     class: 'layui-btn layui-btn-xs layui-btn-success',
                            //     method: 'open',
                            //     text: '查看二维码',
                            //     auth: 'order',
                            //     url: init.order_index_url,
                            //     // extend: 'data-full="true"',
                            // }
                            ],
                            'delete']

                    },
                ]],
            });

            ea.listen();
        },
        add: function () {
            ea.listen();
        },
        edit: function () {
            ea.listen();
        },
        order_index: function () {
            var id = GetQueryString('id');
            init.index_url = init.order_index_url+"?id="+id;
            ea.table.render({
                init: init,
                // totalRow: true,
                toolbar: ['refresh'
                ]
                ,
                cols: [[
                    {type: 'checkbox'},
                    {field: 'id', title: 'ID',search:false},
                    {field: 'qr_code', title: '二维码',search:false},
                    {field: 'qr_user_id', title: '生成二维码用户',templet: ea.table.image,search:false},

                    {field: 'class_name', title: '班级',search:false},
                    {field: 'class_desc', title: '班级描述',search:false},

                    {field: 'class_time', title: '上课时间',search:false},
                    {field: 'evaluate_period_time', title: '评价截至时间',search:false},

                    {field: 'create_time', title: '添加时间',search:"range",hide:true},
                    {width: 250, title: '操作', templet: ea.table.tool},
                ]],
                parseData: function(res){ //将原始数据解析成 table 组件所规定的数据
                    return {
                        "code": res.code, //解析接口状态
                        "msg": res.msg, //解析提示文本
                        "count": res.count, //解析数据长度
                        "data": res.data, //解析数据列表
                        // "totalRow": {
                        //     "allordernum": "总完成订单数："+res.allordernum,
                        //     "allorderprice": "总完成订单价格："+res.allorderprice,
                        //
                        // }
                    };
                }
            });
            ea.listen();
        },
        setQrcode:function () {
            ea.listen();
        },
    };
    return Controller;
});